#!/usr/bin/python
# -*- coding: UTF-8 -*-

import pymysql

# 打开数据库连接
db = pymysql.connect(host="172.28.50.12",port=3306, user="root", passwd="9A7FEa98sP", db="checkmail", charset='utf8' )

# 使用cursor()方法获取操作游标
cursor = db.cursor()

# 使用execute方法执行SQL语句
cursor.execute("SELECT VERSION()")

# 使用 fetchone() 方法获取一条数据
data = cursor.fetchone()

print ("Database version : %s " % data)

# 查询数据
sql = "SELECT * FROM mail WHERE sendmail = '%s' "
data = ('j72@063training.com',)
cursor.execute(sql % data)
for row in cursor.fetchall():
    print(row)
print('共查找出', cursor.rowcount, '条数据')

# 关闭数据库连接
db.close()